#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <istream>
#include <limits>

using ll = int64_t;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    freopen("chess.in", "r", stdin);
    freopen("chess.out", "w", stdout);
    ll t;
    std::cin>>t;
    while(t--){
        ll n,m,sx,sy,tx,ty;
        std::cin>>n>>m>>sx>>sy>>tx>>ty;
        ll ans=std::numeric_limits<ll>::max();
        for(ll i=-1;i<=1;i++){
            for(ll j=-1;j<=1;j++){
                ll nx=tx+n*i;
                ll ny=ty+m*j;
                ll ansx=abs(nx-sx);
                ll ansy=abs(ny-sy);
                ans=std::min(ans,std::max(ansx,ansy));
            }
        }
        std::cout<<ans<<'\n';
    }
}